﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;

namespace MailBodyFormatter
{
    public class MailBody
    {
        static string   strMailTemplate = @"Hi {name},

Thanks for your interest in our Los Pinos Condo at Breckenridge ({webaddress}).

The dates you requested are still available for your party of {numInParty} ({nights} nights, starting {checkinDate}).

The rental charges for your stay will be {rent}, including taxes {tax}, your total charges will be {rentWithTax}.

The cleaning fee is included in the rate quoted above. I use an in-town property manager who will take care of the pre and post cleaning. The property manager will also help with any questions or concerns that you might have during your stay.

In order to confirm this reservation, we require a 50% deposit and an Email confirmation that you agree to the terms as in http://tinyurl.com/breckenridgeCondoPolicy.  I will send you details for payment as soon as I hear the confirmation from you.

Our home is located very near the snowflake lifts. During Winter, you can Ski Out/ Walk in to/from the snowflake lifts. It is a very easy walk to the Mainstreet or you can take the free shuttle that stops in front of the Complex. You can also take advantage of the nice hot tub in the Condo complex and the free access to the upper village swimming pool.  There are also plenty of casual and fine-dining choices nearby.  Our kitchen is fully-equipped with plenty of cooking gear, nice appliances, and refrigerator, microwave and dishwasher if you choose to cook.

I look forward to hearing back from you and reserving your stay at our beautiful Los Pinos, Breckenridge Condo ({webaddress}).

Regards,
Mana 
Email: peak9place@gmail.com
Phone: 720-837-COZY
Website: {webaddress}
Calendar: {webaddress}#calendar
";

        static string strBookedTemplate = @"
Dear {name},
 
Thank you for your interest in our Los Pinos Condo at Breckenridge.  Some of the dates of your interest are already booked.  However, we have availablility adjacent to your originally requested dates (check the chart below this Email). please also check our online calendar at {webaddress}#calendar  to see if any of those available dates will fit your schedule. 
 
Our home is located very near the snowflake lifts. You can Ski Out/ Walk in  to/from the snowflake lifts. It is a very easy walk to the Mainstreet or you can take the free shuttle that stops in front of the Complex. You can also take advantage of the nice hot tub in the Condo complex.  There are also plenty of casual and fine-dining choices nearby.  Our kitchen is fully-equipped with plenty of cooking gear, nice appliances, and refrigerator, microwave and dishwasher if you choose to cook.
 
I look forward to hearing back from you and hopefully reserving your stay at our beautiful Los Pinos, Breckenridge Condo ({webaddress}).  
 
Regards,
Mana 
Email: peak9place@gmail.com
Phone: 720-837-COZY
Website: {webaddress}
Calendar: {webaddress}#calendar
";



        public static string GetFormattedBody(string webaddress, string name, string numInParty, double rent, double tax,  int nights, DateTime checkinDate, bool booked )
        {
            string newStr = string.Empty;
            var  replacements = new Dictionary<string, string>();
            replacements["name"] = string.Format("{0}", name);
            replacements["webaddress"] = string.Format("{0}", webaddress);
            replacements["numInParty"] = string.Format("{0}", numInParty);
            replacements["nights"] = string.Format("{0}", nights);
            replacements["checkinDate"] = string.Format("{0}", checkinDate.ToString("MMMM dd, yyyy"));
            replacements["rent"] = string.Format("${0:#,###.##}", rent);
            replacements["tax"] = string.Format("${0:#,###.##}", tax );
            replacements["rentWithTax"] = string.Format("${0:#,###.##}", rent + tax);

            Regex regex = new Regex(@"\{(?<key>\w+)\}");
            if (!booked)
            {
                newStr = regex.Replace(strMailTemplate, 
                    match=>replacements[match.Groups[1].Captures[0].Value]);
            }
            else
            {
                newStr = regex.Replace(strBookedTemplate, 
                    match=>replacements[match.Groups[1].Captures[0].Value]);
            }

            return newStr;
            
        }
    }
}
